# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: David Runge <dvzrv@archlinux.org>
# Contributor: Stijn Segers <francesco dot borromini at gmail dot com>

_name=FreeRDP
pkgname=freerdp
pkgver=2.10.0
pkgrel=3
epoch=2
pkgdesc="Free implementation of the Remote Desktop Protocol (RDP)"
arch=(loong64 x86_64)
url="https://www.freerdp.com/"
license=(Apache)
depends=(
  glibc
  libcups
  libx11
  libxcursor
  libxext
  libxdamage
  libxfixes
  libxkbcommon
  libxi
  libxinerama
  libxkbfile
  libxrandr
  libxrender
  libxtst
  pcsclite
  wayland
)
makedepends=(
  alsa-lib
  cmake
  docbook-xsl
  ffmpeg
  icu
  krb5
  libjpeg-turbo
  libpulse
  libusb
  openssl
  pam
  systemd
  xmlto
  xorgproto
)
provides=(
  libfreerdp2.so
  libfreerdp-client2.so
  libfreerdp-server2
  libfreerdp-shadow2.so
  libfreerdp-shadow-subsystem2.so
  libwinpr2.so
  libwinpr-tools2.so
  libuwac0.so
)
source=(
  https://github.com/$pkgname/$pkgname/archive/$pkgver/$pkgname-$pkgver.tar.gz
  $pkgname-2.0.0-manpage_formatting.patch
  https://github.com/FreeRDP/FreeRDP/commit/aa2cb9aa.patch
)
sha512sums=('388c00d2f883b41d4ec127bcb871607429c136bfb99daf87f491e9f1e7d456e1fac403db9f9dec7611e729dfd2f913fa414ed3d0020d92c284c8f3ba1eeb80cb'
            'd960e042d1527b5d5721136b6b20fc36f65beafd010581ea5b908668537fe9fe622de6689a29c0274b0d6f1e513615f0d02e56c1d1d1e613d093e145d39af8d7'
            '252e489b4136aab2127f63aab21c790165f9993d967634768ef02d53d8403564336edb9c764a509b46b3303f56008da3477b56caf18c3ff3cc56f4a60686bc5f')
b2sums=('1ca36b227fc9f04371587a8db5a85fb3af0453a6b0c51d981c8e41ecfd9994b3ce48f8c94b0c5c61223ed1a061f3ba800117ed01d5d49b4c2e7a9b5598888d1e'
        '8242fe56ba9cf5352d836f656645a46142c1aecea3e8200203117a0cccc226135591c16fa0a24cfa196ade7b703832ff6871a948fd3bbbcc1d9c6df9885dc360'
        'e404919f3203dcbf53e31b767e189a80522ffa4b53c8c656516da978700cc33eed8798c9c0c89ceb08397e5effa4a854e96daebcab46adc6be912b0d225c304f')

prepare() {
  # fix man page formatting:
  # https://bugs.archlinux.org/task/64814
  patch -d $_name-$pkgver -p1 -i ../$pkgname-2.0.0-manpage_formatting.patch
  patch -d $_name-$pkgver -p1 -i ../aa2cb9aa.patch # Fix build with FFmpeg 6
}

build() {
  local cmake_options=(
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_INSTALL_LIBDIR=lib
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_SKIP_INSTALL_RPATH=ON
    -DPROXY_PLUGINDIR=/usr/lib/freerdp2/server/proxy/plugins
    -DWITH_DSP_FFMPEG=ON
    -DWITH_FFMPEG=ON
    -DWITH_PULSE=ON
    -DWITH_CUPS=ON
    -DWITH_PCSC=ON
    -DWITH_ICU=ON
    -DWITH_JPEG=ON
    -DWITH_SERVER=ON
    -DWITH_SWSCALE=ON
    -DWITH_CHANNELS=ON
    -DWITH_CLIENT_CHANNELS=ON
    -DWITH_SERVER_CHANNELS=ON
    -DCHANNEL_URBDRC_CLIENT=ON
    -Wno-dev
    -B build
    -S $_name-$pkgver
  )

  cmake "${cmake_options[@]}"
  cmake --build build --verbose
}

check() {
  ctest --test-dir build --output-on-failure
}

package() {
  depends+=(
    alsa-lib libasound.so
    ffmpeg libavcodec.so libavutil.so libswresample.so libswscale.so
    icu libicuuc.so
    libjpeg-turbo libjpeg.so
    libpulse libpulse.so
    libusb libusb-1.0.so
    openssl libcrypto.so libssl.so
    pam libpam.so
    systemd-libs libsystemd.so
  )

  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 $_name-$pkgver/{ChangeLog,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
}
